<?php

class CategoryController extends Controller
{
	public function actionIndex()
	{
      $id = Yii::app()->request->getParam('id',0);
      $criteria = new CDbCriteria();
      
      $this->layout = 'shop';
      $model = new Books();
      $page = Yii::app()->request->getParam('page',1);
      $limit = 9;
      $offset = $page * $limit - $limit;
      if($id > 0){
         $criteria->addCondition('book_cat_id = ' . $id);
      }
      $criteria->offset = $offset;
      $criteria->limit = $limit;
      $pagination = new Zebra_Pagination();
      $pagination->records(Books::model()->count($criteria));
      $pagination->records_per_page($limit);
      $models = Books::model()->with('publisher')->findAll($criteria);
      $category = Category::model()->findByPk($id);
		$this->render('index',array(
         'model' => $model,   
         'models' => $models,
         'category' => $category,
         'pagination' => $pagination,
      ));
	}

	// Uncomment the following methods and override them if needed
	/*
	public function filters()
	{
		// return the filter configuration for this controller, e.g.:
		return array(
			'inlineFilterName',
			array(
				'class'=>'path.to.FilterClass',
				'propertyName'=>'propertyValue',
			),
		);
	}

	public function actions()
	{
		// return external action classes, e.g.:
		return array(
			'action1'=>'path.to.ActionClass',
			'action2'=>array(
				'class'=>'path.to.AnotherActionClass',
				'propertyName'=>'propertyValue',
			),
		);
	}
	*/
}